<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>阻止默认行为</title>
  </head>
  <body>
    <a href="https://baidu.com" id="baidu">百度</a>

    <form action="index.java">
      <input type="submit" value="登录" />
    </form>

    <script>
      // 默认行为：即标签默认的动作。如a标签、form表单标签

      let aEle = document.getElementById("baidu");
      aEle.addEventListener("click", function (event) {
        event.preventDefault(); // 阻止标签的默认行为
        alert("弹");
      });
    </script>
  </body>
</html>
